home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / AmigaTalk / examples / prime.st < prev    next >
Text File  |  1998-09-30  |  494b  |  26 lines

  1. Class Main
  2. [
  3.    main   | x gen |
  4.       gen <- Primes new.
  5.       (smalltalk time: [ x <- gen first.
  6.       [x < 300]
  7.          whileTrue: [ x print. x <- gen next] ] ) print.
  8. ]
  9. Class Primes
  10. | lastPrime |
  11. [
  12.    first
  13.       ^ lastPrime <- 2
  14. |
  15.    next
  16.       [lastPrime <- lastPrime + 1.
  17.        self testNumber: lastPrime]
  18.          whileFalse.
  19.       ^ lastPrime
  20. |
  21.    testNumber: n
  22.       (Primes new) do: [:x | 
  23.          (x squared > n) ifTrue: [ ^ true ].
  24.          (n \\ x = 0) ifTrue: [ ^ false ] ]
  25. ]
  26.